package com.xinda.admin.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xinda.admin.pojo.ProductStyle;
import com.xinda.admin.service.IStyleService;

@Controller
public class StyleController {

	@Autowired
	@Qualifier("styleService")
	private IStyleService styleService;
	
	@RequestMapping(value="styleList")
	public String showStyleListPage(Model model){
		List<ProductStyle> styleList = styleService.queryStyleList();
		model.addAttribute("styleList", styleList);
		model.addAttribute("count", styleList.size());
		return "admin/style/styleList";
	}
	
	@RequestMapping(value="styleUpdateOfStatus")
	@ResponseBody
	public void updateStatusById(int id, int status){
		styleService.updateStatusById(id, status);
	}
	
	@RequestMapping(value="showEditStylePage")
	public String showEditPage(int id,Model model){
		ProductStyle style = styleService.queryStyleById(id);
		model.addAttribute("style", style);
		return "admin/style/editStyle";
	}
	
	@RequestMapping(value="deleteStyle")
	@ResponseBody
	public void deleteStyleById(int id){
		styleService.deleteStyleById(id);
	}
	
	@RequestMapping(value="showAddStylePage")
	public String showAddStylePage(){
		return "admin/style/addStyle";
	}
	
	@RequestMapping(value="updateStyle")
	@ResponseBody
	public void editStyle(ProductStyle style) {
		styleService.updateStyle(style);
	}
	
	@RequestMapping(value="addStyle")
	@ResponseBody
	public void addStyle(ProductStyle style) {
		styleService.addStyle(style);
	}
}
